<template>
    
    <!-- 组件的模板 -->
  
   <div class="page show-topbar show-tabbar" :class="{'blur': insurance || insurance_success}">
        <div class="topbar">
        <!-- <div class="topbar"> -->
            <span class="date" @click="selectDate">
                <span class="bg_sprite icon-calendar"></span>{{yymmdd}}
            </span>
            <!-- <span class="time" v-show="extra_info.work_type==1">今天已工作{{extra_info.work_hours}}</span> -->
            <span class="time" v-if='isToday'>今天工作{{extra_info.work_hours || '0小时0分钟'}}</span>
            <span class="time" v-else>当天工作{{extra_info.work_hours || '0小时0分钟'}}</span>
        </div>
        <empty :msg.sync="message" :show-empty="showEmpty"></empty>
        <div class="process" v-show="!showEmpty&&isToday">
             <div class="module" v-for="attendance in attendance_list">
                <span class="bg_sprite" :class="{'state state_2':attendance.statusClass==2,'state state_3':attendance.statusClass==3,'state state_1':attendance.statusClass==1}"></span>
                <span class="line"></span>
                <div class="wrap">
                    <!-- <div class="top" @click="gotoKqSingleDetail(attendance)"> -->
                    <div class="top">
                        <span class="title" v-if="attendance.type == 1">上班 {{attendance.require_time}}</span>
                        <template v-if="attendance.type == 2">
                            <div class="fl" v-if="!attendance.require_time&&!attendance.attend_time&&left_time_str>0&&attendance_list[0].attend_time">
                                <span class="title">下班 {{attendance.require_time}}</span>
                                <p class="tip">{{left_time}}后即可下班</p>
                            </div>
                            <span class="title" v-else>下班 {{attendance.require_time}}</span>
                        </template>
                        

                        <template v-for="item in attendance.status">
                            <span :class="{'tag tag_2':attendance.statusClass==2,'tag tag_3':attendance.statusClass==3}">{{item.name}}</span>
                        </template>
                        <!-- <div class="fr">
                            <span v-if="attendance.attend_time" class="time">{{attendance.attend_time}}</span>
                            <a v-if="attendance.status.length>0&&attendance.status[0].value==6&&attendance.update_btn==1" @click="toClock(attendance)">重新打卡</a>
                        </div>
                       <template v-if="attendance.attendance_btn==1">
                            <a class="button"  v-if="attendance.type == 1" @click="toClock(attendance)">签到</a>
                            <a class="button" v-if="attendance.type == 2" @click="toClock(attendance)">签退</a>
                       </template> -->
                       <div class="fr">
                            <span v-if="attendance.attend_time && attendance.status[0].value!=6" class="time">{{attendance.attend_time}}</span>
                           <template v-if="attendance.attendance_btn==1 || (attendance.update_btn==1&&attendance.status[0].value==6)">
                                <a class="button"  v-if="attendance.type == 1" @click="toClock(attendance)">签到</a>
                                <a class="button" v-if="attendance.type == 2" @click="toClock(attendance)">签退</a>
                           </template>
                       </div>
                    </div>
                    <template v-if="attendance.attendance_id">
                        <template v-if="attendance.position">
                            <p class="location" v-if="attendance.position_name">
                                <span class="bg_sprite icon-location"></span>{{attendance.position_name}} ({{attendance.position}})
                            </p>
                            <p class="location" v-else>
                                <span class="bg_sprite icon-location"></span>{{attendance.position}}
                            </p>
                        </template>
                        
                        <div class="pic-wrap" v-if="attendance.photo.length||(attendance.status[0].value!=6&&attendance.update_btn==1)">
                            <ul class="pic-list" v-if="attendance.photo.length">
                                <li v-for="photoItem in attendance.photo" track-by="$index">
                                    <img :src="photoItem.thumb_url" alt="" v-if="$index<2" @click="picPreview($index,attendance.photo)">
                                    <div class="mask" v-if="$index==1" @click="picPreview($index,attendance.photo)"><span></span><span></span><span></span></div>
                                </li>
                            </ul>
                            <a class="link"  v-if="attendance.status[0].value!=6&&attendance.update_btn==1" @click="toClock(attendance)">重新打卡</a>
                        </div>
                        <div class="remark" v-if="attendance.remark"><em>备注</em>{{attendance.remark}}</div>
                        <div class="remark tip" v-if="attendance.actionText">
                            {{attendance.actionText}}
                        </div>
                    </template>
                </div>
            </div> 
        </div>

        <!-- 个人考勤记录 -->

        <!-- <empty :msg.sync="message" :show-empty="showEmpty"></empty> -->
        <div class="page" v-show="!showEmpty&&!isToday">
            <!-- <div class="mod-user com-border-bottom" v-if="!isMine" @click="toProjectMemberDetail">
                <a href="javascript:;">
                    <div class="avatar-box">
                        <img v-if="extra_info.logo.thumb_url" class="avatar" :src="extra_info.logo.thumb_url">
                        <img v-else class="avatar" src="../../static/imgs/avatar.png">
                        <span class="cover" v-if="status_id == -1">已删除</span>
                    </div>
                    <div class="info">
                        <p class="name">{{extra_info.name}}</p>
                        <p class="team">{{extra_info.group_name}}</p>
                    </div>
                </a>
            </div> -->
            <div class="process">             
                <div class="module" v-for="attendance in attendance_list">
                    <span class="bg_sprite" :class="{'state state_2':attendance.statusClass==2,'state state_3':attendance.statusClass==3,'state state_1':attendance.statusClass==1}"></span>
                    <span class="line"></span>
                    <div class="wrap">
                        <div class="top"> 
                            <span class="title" v-if="attendance.type == 1">上班 {{attendance.require_time}}</span>
                            <span class="title" v-if="attendance.type == 2">下班 {{attendance.require_time}}</span>
                            <template v-for="item in attendance.status">
                                <span :class="{'tag tag_2':attendance.statusClass==2,'tag tag_3':attendance.statusClass==3}">{{item.name}}</span>
                            </template>
                            <div class="fr" >
                                <span v-if="attendance.attend_time" class="time">{{attendance.attend_time}}</span>
                                <a v-if="changePermission&&attendance.status.length>0&&attendance.status[0].value==6" @click="resetToNormal(attendance)">改为正常</a>
                            </div>
                        </div>
                        <template v-if="attendance.attendance_id">
                            <template v-if="attendance.position">
                                <p class="location" v-if="attendance.position_name" @click="toPositionMap(attendance.attendance_id)">
                                    <span class="bg_sprite icon-location"></span>{{attendance.position_name}} ({{attendance.position}})
                                </p>
                                <p class="location" v-else @click="toPositionMap(attendance.attendance_id)">
                                    <span class="bg_sprite icon-location"></span>{{attendance.position}}
                                </p>
                            </template>
                            
                            <div class="pic-wrap" v-if="attendance.photo.length||(changePermission&&attendance.status[0].value!=6&&attendance.statusClass==3)">
                                <ul class="pic-list" v-if="attendance.photo.length">
                                    <li v-for="photoItem in attendance.photo" track-by="$index">
                                        <img :src="photoItem.thumb_url" alt="" v-if="$index<2" @click="picPreview($index,attendance.photo)">
                                        <div class="mask" v-if="$index==1" @click="picPreview($index,attendance.photo)"><span></span><span></span><span></span></div>
                                    </li>
                                </ul>
                                <a class="link" v-if="changePermission&&attendance.status[0].value!=6&&attendance.statusClass==3" @click="resetToNormal(attendance)">改为正常</a>
                            </div>
                            <div class="remark" v-if="attendance.remark"><em>备注</em>{{attendance.remark}}</div>
                            <div class="remark tip" v-show="attendance.actionText">
                                {{attendance.actionText}}
                            </div>
                        </template>
                      
                    </div>
                </div>                        
            </div>        
        </div>
    </div>  

    <template v-if="insurance">
        <div class="weui-mask" style="background: rgba(0, 0, 0, 0.75);"></div>
        <div class="popup_insurance">
            <p class="tip">斗米兼职为您免费办理保险，请输入 真实姓名、身份证领取保险</p>
            <div class="form-wrap">
                <div class="item">
                    <input type="text" name="" placeholder="真实姓名" v-model="realName">
                </div>
                <div class="item">
                    <input type="text" name="" placeholder="身份证号码" v-model="identityCode">
                </div>            
                <a class="button" href="javascript:;" @click="receiveInsurance">领取保险</a>
                <p class="link"><a href="javascript:;" @click="latterReceive">稍后领取</a></p>
            </div>
        </div>
    </template>

    <template v-if="insurance_success">
        <div class="weui-mask" style="background: rgba(0, 0, 0, 0.75);" @click="receiveSuccess"></div>
        <div class="popup_insurance_success" @click="receiveSuccess">
            <img class="icon_insurance" src="../../static/imgs/icon_insurance.png" alt="">
            <span class="tip">领取成功!</span>
        </div>
    </template>
</template>
  
<script>
     let ajaxDate = {}
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    import widget from 'gapi/widget'
    import * as util from 'js/util.js'
    import cache from 'gapi/cache.js'
    import Empty from 'components/Empty/Empty'
    import commonPage from 'clientApi/commonPage.js'
    commonPage.canPullWebView(false)
    import clientUi from 'gapi/clientUi'
    import KCApiApp from 'clientApi/KCApiApp.js'
    import teamApi from 'clientApi/teamApi.js'



    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    /**
     *  组件实例对象
     */
    export default {
        components: {
            Empty
        },
        data: function(){
            return {
                extra_info:{
                    date: new Date().getTime()/1000
                },
                attendance_list: [],
                message:'当日没有安排考勤任务',
                showEmpty:false,
                isToday: true,
                today: '',//今日日期  2017-2-14
                kqdate: '',
                permission: [],
                // should_work_hours: 8,//弹性工作制时，应该工作的时长
                left_time: '',//x小时x分钟
                left_time_str: 0,//剩余时间的时间戳
                insurance: false,//是否弹出领取保险
                insurance_success: false,//领取成功
                identityCode: '',//领取保险人身份证号码
                realName: '',//领取保险人填写姓名
                mobile: 0,//领取保险时带来的手机号
            }
        },
        computed: {
            yymmdd: function(){
                return util.getLocalTime(this.extra_info.date * 1000, 'yyyy年MM月dd日')
            },
            changePermission(){
                let boo = false
                this.permission.forEach((item)=>{
                    if(item.id_name=='attendance_status_change'){
                        boo = true
                    }
                })
                return boo
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                ajaxDate.project_id = util.getUrddataString('project_id') || util.getQueryString('project_id')
                ajaxDate.team_id = util.getUrddataString('team_id') || util.getQueryString('team_id')
                ajaxDate.user_id = util.getUrddataString('user_id') || util.getQueryString('user_id')
                cache.setCache('KqCacheMessge',ajaxDate,10 * 24 * 60 * 60)
                //获取今日考勤信息
                this.getDate()

                //bug: 如果登录期间权限有所修改 缓存不会更新  故 不应用缓存
                // cache.getMemoryCache('kqPermission',(data)=>{
                //     if(data){
                //         this.permission = data.data
                //     }else{
                        this.getPermission()
                    // }
                // })

                //弹性工作制时  计算剩余签退时间
                // console.log(this.attendance_list[0].require_time === undefined)
                let timer = setInterval(() => {
                    if(this.attendance_list.length > 0){//获取到数据后执行
                        if(!this.attendance_list[0].require_time){//判断是弹性工作制
                            if(this.today&&this.attendance_list[0].attend_time){//是今天 并且已经打了上班卡
                                // console.log(111)
                                let timestr1 = util.getStampFromDate(this.today+" "+this.attendance_list[0].attend_time)//上班的时间戳
                                let cur_time = new Date().getTime()
                                this.left_time_str = timestr1 + this.extra_info.work_time_length*60*1000 + 60*1000 - cur_time//剩余工作时长的时间戳
                                if(this.left_time_str <= 0) {
                                    this.left_time_str = 0
                                    clearInterval(timer)
                                }
                                this.left_time = parseInt(this.left_time_str/1000/60/60) + '小时' + parseInt(this.left_time_str/1000/60%60) + '分钟'

                            }
                        }else{
                            //标准时间制
                            clearInterval(timer)
                        }
                    }
                    // console.log('timer')
                    
                }, 1000)

                //判断所在团队是否有保险应用  之后再掉完善资料接口
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/application/vision/area',
                    type: 'GET',
                    data: {
                        team_id: ajaxDate.team_id,
                        project_id: ajaxDate.project_id
                    },
                    timeout: 10000,
                    success: (data) => {
                        // success
                        // alert(JSON.stringify(data))
                        console.log('app')
                        console.log(data)
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){
                            data.data.result.forEach((obj) => {
                                if(obj.app_id == 5){
                                    // alert(123)
                                    //是否购买保险
                                    //判断是否领取保险
                                    // console.log(this.user_id)
                                    // return
                                    commonPage.loadPageStatus('loading')
                                    util.ajax({
                                        url: '/insurance/user_info/get',
                                        type: 'GET',
                                        data: {
                                            team_id: ajaxDate.team_id,
                                            project_id: ajaxDate.project_id,
                                            type: 1//区分是考勤(1)还是签到(2)
                                        },
                                        timeout: 10000,
                                        success: (data) => {
                                            // success
                                            // alert(JSON.stringify(data))
                                            console.log(data)
                                            commonPage.loadPageStatus('loadSuccess')
                                            if(data.errno == 0){
                                                if(data.data[0].status == 1){//需要填写
                                                    this.insurance = true
                                                    this.identityCode = data.data[0].info.id_number ? data.data[0].info.id_number : ''
                                                    this.realName = data.data[0].info.name ? data.data[0].info.name : ''
                                                    ajaxDate.user_id = data.data[0].info.user_id
                                                    this.mobile = data.data[0].info.mobile

                                                    //调用API隐藏底部tabBar
                                                    teamApi.updateBottomStatus(0)
                                                }
                                            }else{
                                                // widget.toast(data.errmsg)
                                                // alert(JSON.stringify(data))
                                            }
                                        },
                                        error: (xhr, status) => {
                                            commonPage.loadPageStatus('loadSuccess')
                                            widget.toast('服务器异常')
                                            // error
                                        },
                                        noNetwork: () => {
                                            // 无网络的回调
                                            commonPage.loadPageStatus('loadSuccess')
                                            widget.toast('网络连接失败，请检查网络')
                                        }
                                    })
                                }
                            })
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                        // error
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })

                
            },
            getDate(lable){//获取的不是今日数据时  传入 true
                let url = '/attendance/user_attendance'
                let data = {
                    'team_id': ajaxDate.team_id,
                    'project_id': ajaxDate.project_id,
                    // 'user_id': ajaxDate.user_id,
                    'date': this.kqdate 
                }
                if(this.today != this.kqdate){
                    //不是今天时的信息
                    url = '/attendance/user_attendance'
                    data = {
                        team_id: ajaxDate.team_id,
                        project_id: ajaxDate.project_id,
                        // user_id: ajaxDate.user_id,
                        date: this.kqdate,
                        // task_id: ''
                    }
                }
                console.log(data)

                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: url,
                    data: data,
                    success: (res) => {
                        console.log(res)
                        commonPage.loadPageStatus('loadSuccess')

                        if(lable){//为的等切换完数据后再切换视图
                           this.isToday = false
                        }else{
                            this.isToday = true
                        }
                        // res = JSON.parse(res)  
                        if(res&&res.errno==0){
                            this.showEmpty = false
                             this.extra_info = res.data.extra_info
                             this.attendance_list = res.data.attendance_list
                             // this.attendance_list[0].status[0].value = 6
                             
                             this.formatDate()
                             if(!this.today){
                                this.today = this.kqdate = util.getLocalTime(this.extra_info.date * 1000, 'yyyy-MM-dd')
                             }

                             
                        }else if(res.errno==21015){
                            this.extra_info.work_hours = '0小时0分钟'
                             this.showEmpty = true
                             if(!this.today){//如果不存在 说明今天没有考勤任务
                                this.extra_info.date = new Date().getTime()/1000
                                this.today = this.kqdate = util.getLocalTime(this.extra_info.date * 1000, 'yyyy-MM-dd')
                             }
                             // console.log(this.extra_info.date)
                             // console.log(this.kqdate)
                        }else if(res.errmsg){
                             widget.toast(res.errmsg)
                        }else{
                             widget.toast('数据获取失败')
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            formatDate(){
                this.attendance_list.forEach((o,i,a)=>{
                    let statusList = o.status
                    let action_log = o.action_log
                    if(o.attendance_id){
                        if(statusList.length==1&&statusList[0].value==1){
                            o.statusClass = 2
                        }else{
                            o.statusClass = 3
                        }
                    }else{
                        if(statusList.length==1&&statusList[0].value==6){
                            o.statusClass = 3
                        }else{
                            o.statusClass = 1
                        }
                    }
                    if(action_log.status&&action_log.status.length){
                        let actionTime = util.getLocalTime(action_log.action_time*1000,'yyyy-MM-dd HH:mm')
                        let text = actionTime + " " + action_log.admin_name + "将"
                        action_log.status.forEach((o,i,a)=>{
                            if(i<action_log.status.length-1){
                                text += o.name + "、"
                            }else{
                                text += o.name + "改为正常"
                            }
                        })
                        o.actionText = text
                    }
                })
            },
            toClock(attendance){
                if(!this.attendance_list[0].require_time && attendance.type == 2 && this.left_time_str > 0 && !attendance.attend_time){
                    
                    clientUi.showDialog('提醒', '现在签退还不满足' + this.extra_info.work_time_length/60 + '小时的工作时间要求，是否继续签退？', (status) => {
                        // console.log(status)
                        if(status.status === '1'){
                            let data = {}
                            data.examples_img_url = this.extra_info.examples_img_url || []  //示例图片
                            data.example_img_thumb_url = this.extra_info.example_img_thumb_url || []  //示例图片 缩略图
                            data.adjust = this.extra_info.adjust || 0   //是否允许地点微调
                            data.adjust_distance = this.extra_info.adjust_distance || 0   //地点微调距离
                            data.project_id = ajaxDate.project_id
                            data.team_id = ajaxDate.team_id
                            data.time_id = attendance.time_id
                            data.attendance_id = attendance.attendance_id
                            data.task_id = this.extra_info.task_id
                            data.name = this.extra_info.user_name
                            data.require_field = this.extra_info.require_field
                            cache.setMemoryCache('KaoqinEditInfo', data)
                            window.location.href="dmsaas://KaoqinEditInfo"
                        }
                    })
                }else{
                    let data = {}
                    data.examples_img_url = this.extra_info.examples_img_url || []  //示例图片
                    data.example_img_thumb_url = this.extra_info.example_img_thumb_url || []  //示例图片 缩略图
                    data.adjust = this.extra_info.adjust || 0   //是否允许地点微调
                    data.adjust_distance = this.extra_info.adjust_distance || 0   //地点微调距离
                    data.project_id = ajaxDate.project_id
                    data.team_id = ajaxDate.team_id
                    data.time_id = attendance.time_id
                    data.attendance_id = attendance.attendance_id
                    data.task_id = this.extra_info.task_id
                    data.name = this.extra_info.user_name
                    data.require_field = this.extra_info.require_field
                    cache.setMemoryCache('KaoqinEditInfo', data)
                    window.location.href="dmsaas://KaoqinEditInfo"
                }
            },
            picPreview (index,imgList){
                let list = []
                imgList.forEach((item)=>{
                    list.push(item.url)
                })
                clientUi.bigPicturePreview('预览', list, index)
            },
            selectDate(){
                

                KCApiApp.showDatePicker('2000-01-01', this.today, this.kqdate, (data) => {
                    this.kqdate = data.SelectedDate
                    // alert(JSON.stringify(this.signDateArr))
                    if(this.today != this.kqdate){
                        // this.isToday = false
                        //获取对应日期考勤信息
                        this.getDate(true)
                    }else{
                        // this.isToday = true
                        //获取对应日期考勤信息
                        this.getDate()
                    }
                    
                    this.extra_info.date = util.getStampFromDate(data.SelectedDate)/1000
                    //获取对应日期考勤信息
                    // this.getDate()
                })
            },
             // 获取权限
            getPermission(){
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/permission/application',
                    data: {
                        team_id: ajaxDate.team_id,
                        project_id: ajaxDate.project_id,
                        application_id: 1
                    },
                    success: (res) => {
                        console.log(res)
                        commonPage.loadPageStatus('loadSuccess')
                        if(res.errno==0){
                           this.permission = res.data
                        }else{
                            widget.toast(res.errmsg)
                        }
                    },
                    error: (xhr, error) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            /**
             * 改为正常按钮
             * @return {[type]} [description]
             */
            resetToNormal(attendance){ 
                 commonPage.loadPageStatus('loading')
                 let statusList = ''
                 attendance.status.forEach((item)=>{
                    statusList += item.value+','
                 })
                 statusList = statusList.substring(0,statusList.length-1)

                 util.ajax({
                    url: '/attendance/attendance_status/update',
                    type:'POST',
                    data: {
                        'team_id':ajaxDate.team_id,
                        'project_id':ajaxDate.project_id,
                        'attendance_id':attendance.attendance_id,
                        'status':statusList,
                        'user_id':ajaxDate.user_id
                    },
                    success: (res) => {
                        console.log(res)
                        commonPage.loadPageStatus('loadSuccess')
                        if(res.errno==0){
                            //更新考勤信息
                            this.getDate(true)
                        }else if(res.errmsg){
                             widget.toast(res.errmsg)
                        }else{
                           widget.toast('更新失败')
                        }
                    },
                    error: (xhr, error) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            toPositionMap(id){
                window.location.href="dmsaas://KaoqinPositionMap?urdData="+encodeURIComponent(`task_id=${this.taskID}&attendance_id=${id}`)
            },
            //领取保险
            receiveInsurance(){
                if(!this.realName){
                    widget.toast('请输入您的真实姓名')
                    return
                }
                if(!this.identityCode){
                    widget.toast('请输入身份证号码')
                    return
                }
                //校验身份证
                // if(!this.identityCodeValid(this.identityCode)){
                //     widget.toast('身份证号格式错误，请重新输入')
                //     return
                // }
                
                console.log({
                        team_id: ajaxDate.team_id,
                        project_id: ajaxDate.project_id,
                        info: {
                            "user_id": ajaxDate.user_id,
                            "id_number": this.identityCode,
                            "name": this.realName,
                            "mobile": this.mobile
                        }
                    })
                //保存参保人信息
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/insurance/user_info/set',
                    type: 'POST',
                    data: {
                        team_id: ajaxDate.team_id,
                        project_id: ajaxDate.project_id,
                        info: {
                            "user_id": ajaxDate.user_id,
                            "id_number": this.identityCode,
                            "name": this.realName,
                            "mobile": this.mobile
                        }
                    },
                    timeout: 10000,
                    success: (data) => {
                        // success
                        // alert(JSON.stringify(data))
                        console.log(data)
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){

                            //领取保险成功后
                            this.insurance = false
                            this.insurance_success = true
                            // setTimeout(() => {
                            //     this.insurance_success = false
                            // }, 1000)

                        }else{
                            widget.toast(data.errmsg)
                            // alert(JSON.stringify(data))
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                        // error
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })

                
            },
            latterReceive(){
                this.insurance = false
                //显示底部tabBar
                teamApi.updateBottomStatus(1)
            },
            receiveSuccess(){
                this.insurance_success = false
                teamApi.updateBottomStatus(1)
            },
            //校验身份证
            identityCodeValid(code){
                let city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
                let tip = "";
                let pass= true;
                
                if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
                    tip = "身份证号格式错误";
                    pass = false;
                }else if(!city[code.substr(0,2)]){
                    tip = "地址编码错误";
                    pass = false;
                }else{
                    //18位身份证需要验证最后一位校验位
                    if(code.length == 18){
                        code = code.split('');
                        if(code[17] === 'x')code[17]='X'
                        //∑(ai×Wi)(mod 11)
                        //加权因子
                        let factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                        //校验位
                        let parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                        let sum = 0;
                        let ai = 0;
                        let wi = 0;
                        for (let i = 0; i < 17; i++)
                        {
                            ai = code[i];
                            wi = factor[i];
                            sum += ai * wi;
                        }
                        let last = parity[sum % 11];
                        if(parity[sum % 11] != code[17]){
                            tip = "校验位错误";
                            pass =false;
                        }
                    }
                }
                // if(!pass) alert(tip);
                return pass;
            },
            gotoKqSingleDetail(attendance){
                cache.setCache('KaoqinEditInfo',{extra_info: this.extra_info, attendance: attendance}, 100000)
                location.href=`dmsaas://KqSingleDetail`
            }
        },
        created(){
            this.init()

            commonPage.updateTitleBar({
                backAction: 'back',
                leftAction: 'back'
            })

            window.back = () => {
                // if(this.insurance){//如果有填写信息的弹窗 先让弹框消失
                //     this.insurance = false
                //     return
                // }
                commonPage.goBack(1)
            }
            window.loadData = (data)=>{
                if(data.key='yy_kqeditinfo'){
                    this.getDate()
                }
            }
        }
        
    }

    
</script>

<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/attendance.css"></style>
<style type="text/css">
    div.topbar .date::after{
        content: "";
        float: right;
        width: 0;
        height: 0;
        border-width: 6px 5px;
        border-style: solid;
        border-color: rgb(194, 197, 203) transparent transparent;
        margin: 19px 0 0 6px;
        border-radius: 2px;
    }
</style>